package cn.txy.article.service.impl;

import cn.txy.aip.contentcensor.BaiduContentCensorService;
import cn.txy.aip.domain.CensorResult;
import cn.txy.article.dao.CommentRepository;
import cn.txy.article.domain.ArticleType;
import cn.txy.article.mongo.Comment;
import cn.txy.article.query.CommentQuery;
import cn.txy.article.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class CommentServiceImpl implements CommentService {
    @Autowired
    private CommentRepository commentRepository;
    @Autowired
    private BaiduContentCensorService baiduContentCensorService;

    @Override
    public void save(Comment comment) {
        String content = comment.getContent();
        CensorResult commonTextCensorResult = baiduContentCensorService.getCommonTextCensorResult(content);
        if (commonTextCensorResult.getIsPass()){
            commentRepository.save(comment);
        }
        throw new RuntimeException("这里不让说藏话");
    }

    @Override
    public void update(Comment comment) {
        commentRepository.save(comment);
    }

    @Override
    public void del(String id) {
        commentRepository.deleteById(id);
    }

    @Override
    public List<Comment> findByArticleId(Long id) {
        return commentRepository.findByArticleId(id);
    }

    @Override
    public List<Comment> findAll() {
        return commentRepository.findAll();
    }


}
